//
//  ViewController2.m
//  AppSettings
//
//  Created by student on 16/3/16.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController2.h"

@interface ViewController2 ()
@property (weak, nonatomic) IBOutlet UISwitch *wrapSiwtch;
@property (weak, nonatomic) IBOutlet UISlider *wrapSpeed;
@property (weak, nonatomic) IBOutlet UITextView *textView;

@end

@implementation ViewController2

- (void)viewDidLoad {
    [super viewDidLoad];
    //更新页面信息
    [self updateInfo];
    //监听程序进入后台的通知，在系统且回到本程序时，更新以下界面信息
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(updateInfo) name:UIApplicationWillEnterForegroundNotification object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)dealloc
{
    //移除通知（必要）
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    
}
-(void)updateInfo
{
    NSUserDefaults *d = [NSUserDefaults standardUserDefaults];
    self.wrapSiwtch.on = [d boolForKey:@"wrap"];
    self.wrapSpeed.value = [d floatForKey:@"wrapSpeed"];
}
- (IBAction)backBtnPressed:(id)sender
{
    //关闭模态窗口
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)switchChanged:(id)sender
{
    //设置值
    NSUserDefaults *d = [NSUserDefaults standardUserDefaults];
    [d setBool:sender forKey:@"wrap"];
    [d synchronize];
}
- (IBAction)sliderChanged:(id)sender
{
    NSUserDefaults *d = [NSUserDefaults standardUserDefaults];
    [d setBool:sender forKey:@"wrapSpeed"];
    [d synchronize];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
